package com.jsyh.maidu.activity.me;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.jsyh.maidu.R;
import com.jsyh.maidu.config.ConfigValue;
import com.jsyh.maidu.model.EvaluateModle;
import com.jsyh.maidu.presenter.SavaEvaluatePresenter;
import com.squareup.picasso.Picasso;

public class EvalateActivity extends Activity implements View.OnClickListener{

    EvaluateModle.EvaluateMain evaModel;
    ImageView iv_goods,iv_back;
    TextView tv_goodsname,tv_title;
    Button btn_submit;
    EditText et_content;
    ImageView iv_anonymity;
    RatingBar rb_discraption,rb_service,rb_send,rb_trans;
    int anonymity=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_evalate);

    }

    public void InitView()
    {
        evaModel= (EvaluateModle.EvaluateMain) getIntent().getSerializableExtra("evamain");

        iv_goods= (ImageView) findViewById(R.id.iv_evaluate_good);
        tv_goodsname= (TextView) findViewById(R.id.tv_evaluate_goodsname);
        et_content= (EditText) findViewById(R.id.et_evaluate_content);
        iv_anonymity= (ImageView) findViewById(R.id.iv_evaluate_anonymity);
        rb_discraption= (RatingBar) findViewById(R.id.rb_evaluate_dis);
        rb_send= (RatingBar) findViewById(R.id.rb_evaluate_send);
        rb_service= (RatingBar) findViewById(R.id.rb_evaluate_service);
        rb_trans= (RatingBar) findViewById(R.id.rb_evaluate_flow);
        btn_submit= (Button) findViewById(R.id.btn_evaluate_submit);
        tv_title= (TextView) findViewById(R.id.title);
        iv_back= (ImageView) findViewById(R.id.back);

        Picasso.with(this).load(ConfigValue.IMG_IP+evaModel.getGoods_thumb()).into(iv_goods);
        tv_goodsname.setText(evaModel.getGoods_name());
        btn_submit.setOnClickListener(this);
        iv_anonymity.setOnClickListener(this);
        tv_title.setText("商品评价");
        iv_back.setOnClickListener(this);



    }

    @Override
    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.btn_evaluate_submit:
                if (!et_content.getText().toString().equals(""))
                {
                    SavaEvaluatePresenter presenter=new SavaEvaluatePresenter(this);
                    presenter.laodSave(evaModel.getRec_id(), et_content.getText().toString(),rb_discraption.getRating()+"",rb_service.getRating()+"",rb_send.getRating()+"",rb_trans.getRating()+"",anonymity+"");
                }else {
                    Toast.makeText(this,"请填写评价",Toast.LENGTH_LONG).show();
                }

                break;
            case R.id.iv_evaluate_anonymity:
                if (anonymity==1)
                {
                    anonymity=0;
                    iv_anonymity.setImageDrawable(getResources().getDrawable(R.drawable.select_no));
                }else
                {
                    anonymity=1;
                    iv_anonymity.setImageDrawable(getResources().getDrawable(R.drawable.select_yes));
                }
                break;
            case R.id.back:
                finish();
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        InitView();
    }
}
